package com.example.eureka_client.controller;


import com.example.eureka_client.entity.CommentsAgree;
import com.example.eureka_client.entity.CommentsInfo;
import com.example.eureka_client.entity.CommentsReply;
import com.example.eureka_client.httpResult.Result;
import com.example.eureka_client.httpResult.ResultGenerator;
import com.example.eureka_client.service.ICommentsInfoService;
import com.example.eureka_client.service.ICommentsReplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * <p>
 * 父评论表 前端控制器
 * </p>
 *
 * @author plj
 * @since 2022-03-24
 */
@RestController
@RequestMapping("/commentsInfo")
public class CommentsInfoController {
    @Resource
    ICommentsInfoService iCommentsInfoService;

    @Resource
    ICommentsReplyService iCommentsReplyService;

    @ApiOperation(value = "获取回答的所有评论")
    @GetMapping("getAnswerComments")
    public Result getAnswerComments(@RequestParam String answerId){
        return ResultGenerator.genSuccessResult(iCommentsInfoService.getAnswerComments(answerId));
    }

    @ApiOperation(value = "获取评论的所有子评论")
    @GetMapping("getChildComments")
    public Result getChildComments(@RequestParam String fatherCommentsId){
        return ResultGenerator.genSuccessResult(iCommentsReplyService.getChildComments(fatherCommentsId));
    }

    @ApiOperation(value = "添加对回答的评论")
    @PostMapping("addComments")
    public Result addComments(@RequestBody CommentsInfo commentsInfo){
        if(iCommentsInfoService.addComments(commentsInfo)) return ResultGenerator.genSuccessResult();
        else return ResultGenerator.genFailResult("添加失败");
    }

    @ApiOperation(value = "删除评论")
    @PostMapping("delComment")
    public Result delComment(@RequestParam String commentsId){
        if(iCommentsInfoService.removeById(commentsId)) return ResultGenerator.genSuccessResult();
        else return ResultGenerator.genFailResult("删除失败");
    }

    @ApiOperation(value = "添加子评论")
    @PostMapping("addChildComment")
    public Result addChildComment(@RequestBody CommentsReply commentsReply){
        if(iCommentsReplyService.addChildComment(commentsReply)) return ResultGenerator.genSuccessResult();
        else return ResultGenerator.genFailResult("添加失败");
    }

    @ApiOperation(value = "删除子评论")
    @PostMapping("delChildComment")
    public Result delChildComment(@RequestParam String commentsId){
        if(iCommentsReplyService.removeById(commentsId)) return ResultGenerator.genSuccessResult();
        else return ResultGenerator.genFailResult("删除失败");
    }

    @ApiOperation(value = "添加点赞(父评论)")
    @PostMapping("addAgree")
    public Result addAgree(@RequestParam String commentsId, @RequestParam String userID){
        CommentsAgree commentsAgree = new CommentsAgree();
        commentsAgree.setCommentsId(commentsId);
        commentsAgree.setUserId(userID);
        commentsAgree.setType(0);

        if(iCommentsInfoService.addAgree(commentsAgree)) return ResultGenerator.genSuccessResult();
        else return ResultGenerator.genFailResult("添加失败");
    }

    @ApiOperation(value = "取消赞")
    @PostMapping("reAgree")
    public Result reAgree(@RequestParam String commentsId, @RequestParam String userID){
        CommentsAgree commentsAgree = new CommentsAgree();
        commentsAgree.setCommentsId(commentsId);
        commentsAgree.setUserId(userID);
        commentsAgree.setType(0);

        if(iCommentsInfoService.reAgree(commentsAgree)) return ResultGenerator.genSuccessResult();
        else return ResultGenerator.genFailResult("取消失败");
    }

    @ApiOperation(value = "是否赞")
    @PostMapping("isAgree")
    public Result isAgree(@RequestParam String commentsId, @RequestParam String userID){
        CommentsAgree commentsAgree = new CommentsAgree();
        commentsAgree.setCommentsId(commentsId);
        commentsAgree.setUserId(userID);
        commentsAgree.setType(0);

        if(iCommentsInfoService.isAgree(commentsAgree)) return ResultGenerator.genSuccessResult(true);
        else return ResultGenerator.genSuccessResult(false);
    }

    @ApiOperation(value = "添加踩(父评论)")
    @PostMapping("addNotAgree")
    public Result addNotAgree(@RequestParam String commentsId, @RequestParam String userID){
        CommentsAgree commentsAgree = new CommentsAgree();
        commentsAgree.setCommentsId(commentsId);
        commentsAgree.setUserId(userID);
        commentsAgree.setType(1);

        if(iCommentsInfoService.addNotAgree(commentsAgree)) return ResultGenerator.genSuccessResult();
        else return ResultGenerator.genFailResult("添加失败");
    }

    @ApiOperation(value = "取消踩")
    @PostMapping("reNotAgree")
    public Result reNotAgree(@RequestParam String commentsId, @RequestParam String userID){
        CommentsAgree commentsAgree = new CommentsAgree();
        commentsAgree.setCommentsId(commentsId);
        commentsAgree.setUserId(userID);
        commentsAgree.setType(1);

        if(iCommentsInfoService.reNotAgree(commentsAgree)) return ResultGenerator.genSuccessResult();
        else return ResultGenerator.genFailResult("取消失败");
    }

    @ApiOperation(value = "是否踩")
    @PostMapping("isNotAgree")
    public Result isNotAgree(@RequestParam String commentsId, @RequestParam String userID){
        CommentsAgree commentsAgree = new CommentsAgree();
        commentsAgree.setCommentsId(commentsId);
        commentsAgree.setUserId(userID);
        commentsAgree.setType(1);

        if(iCommentsInfoService.isAgree(commentsAgree)) return ResultGenerator.genSuccessResult(true);
        else return ResultGenerator.genSuccessResult(false);
    }


    @ApiOperation(value = "添加点赞(子评论)")
    @PostMapping("addChildAgree")
    public Result addChildAgree(@RequestParam String commentsId, @RequestParam String userID){
        CommentsAgree commentsAgree = new CommentsAgree();
        commentsAgree.setCommentsId(commentsId);
        commentsAgree.setUserId(userID);
        commentsAgree.setType(0);

        if(iCommentsReplyService.addChildAgree(commentsAgree)) return ResultGenerator.genSuccessResult();
        else return ResultGenerator.genFailResult("添加失败");
    }

    @ApiOperation(value = "取消赞(子)")
    @PostMapping("reChildAgree")
    public Result reChildAgree(@RequestParam String commentsId, @RequestParam String userID){
        CommentsAgree commentsAgree = new CommentsAgree();
        commentsAgree.setCommentsId(commentsId);
        commentsAgree.setUserId(userID);
        commentsAgree.setType(0);

        if(iCommentsReplyService.reChildAgree(commentsAgree)) return ResultGenerator.genSuccessResult();
        else return ResultGenerator.genFailResult("取消失败");
    }

    @ApiOperation(value = "是否赞")
    @PostMapping("isChildAgree")
    public Result isChildAgree(@RequestParam String commentsId, @RequestParam String userID){
        CommentsAgree commentsAgree = new CommentsAgree();
        commentsAgree.setCommentsId(commentsId);
        commentsAgree.setUserId(userID);
        commentsAgree.setType(0);

        if(iCommentsReplyService.isChildAgree(commentsAgree)) return ResultGenerator.genSuccessResult(true);
        else return ResultGenerator.genSuccessResult(false);
    }

    @ApiOperation(value = "添加踩(子评论)")
    @PostMapping("addChildNotAgree")
    public Result addChildNotAgree(@RequestParam String commentsId, @RequestParam String userID){
        CommentsAgree commentsAgree = new CommentsAgree();
        commentsAgree.setCommentsId(commentsId);
        commentsAgree.setUserId(userID);
        commentsAgree.setType(1);

        if(iCommentsReplyService.addChildNotAgree(commentsAgree)) return ResultGenerator.genSuccessResult();
        else return ResultGenerator.genFailResult("添加失败");
    }

    @ApiOperation(value = "取消踩")
    @PostMapping("reChildNotAgree")
    public Result reChildNotAgree(@RequestParam String commentsId, @RequestParam String userID){
        CommentsAgree commentsAgree = new CommentsAgree();
        commentsAgree.setCommentsId(commentsId);
        commentsAgree.setUserId(userID);
        commentsAgree.setType(1);

        if(iCommentsReplyService.reChildNotAgree(commentsAgree)) return ResultGenerator.genSuccessResult();
        else return ResultGenerator.genFailResult("取消失败");
    }


    @ApiOperation(value = "是否踩")
    @PostMapping("isChildNotAgree")
    public Result isChildNotAgree(@RequestParam String commentsId, @RequestParam String userID){
        CommentsAgree commentsAgree = new CommentsAgree();
        commentsAgree.setCommentsId(commentsId);
        commentsAgree.setUserId(userID);
        commentsAgree.setType(1);

        if(iCommentsReplyService.isChildAgree(commentsAgree)) return ResultGenerator.genSuccessResult(true);
        else return ResultGenerator.genSuccessResult(false);
    }
}
